package 力扣.树;


import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class N叉树的最大深度559 {
    public static int maxDepth(TreeNode root) {
        Deque<TreeNode> deque = new LinkedList<>();
        int ans = 0 ;//深度
        if (root != null){
            deque.offerFirst(root);
        }
        while (deque.size() > 0){
            final int size = deque.size();
            ans++;
            for (int i = 0; i < size; i++) {
                TreeNode treeNode = deque.pollFirst();
                assert treeNode != null;
                List<TreeNode> childrens = treeNode.children;
                for (TreeNode children: childrens) {
                    deque.offerLast(children);
                }
            }
        }
        return ans;
    }
}
